package cn.anecansaitin.jep;

import cn.anecansaitin.jep.parser.Parser;
import cn.anecansaitin.jep.parser.ast.node.expression.Expression;
import cn.anecansaitin.jep.interpreter.Interpreter;

import java.io.PrintStream;
import java.nio.charset.StandardCharsets;

public class Main {
    static void main() {
        System.setOut(new PrintStream(System.out, true, StandardCharsets.UTF_8));
        Lexer lexer = new Lexer("true || false || false");
        lexer.analyze();
        Parser parser = new Parser(lexer);
        parser.parse();
        Expression expression = parser.getExpression();

        if (expression == null || parser.hasError()) {
            System.out.println("表达式错误");
            for (String[] error : parser.getErrors()) {
                for (String s : error) {
                    System.out.print(s);
                }
            }

            return;
        }

        Interpreter interpreter = new Interpreter();
        Object result = interpreter.evaluate(expression);
        System.out.println(result.getClass() + ": " + result);
    }
}